Page({
  data: {
    banners: [
      { id: 1, image: '/pages/images/banner1.jpg' },
      { id: 2, image: '/pages/images/banner2.jpg' },
      { id: 3, image: '/pages/images/banner3.jpg' },
      { id: 4, image: '/pages/images/banner4.jpg' },
      { id: 5, image: '/pages/images/banner5.jpg' }
    ],
    features: [
      { id: 1, name: '预约取号', iconClass: 'icon-reserve', path: '/pages/reservation/reservation' },
      { id: 2, name: '商家信息', iconClass: 'icon-merchant', path: '/pages/merchant/merchant' },
      { id: 3, name: '环境展示', iconClass: 'icon-environment', path: '/pages/environment/environment' }
    ],
    recommendDishes: [
      {
        id: 1,
        name: '回锅肉',
        price: '17.54',
        description: '精选五花肉+秘制香料',
        image: '/pages/images/dish1.jpg'
      },
      {
        id: 2,
        name: '小炒肉',
        price: '15.80',
        description: '新鲜猪肉+青椒爆炒',
        image: '/pages/images/dish2.jpg'
      },
      {
        id: 3,
        name: '炝炒莲白',
        price: '12.50',
        description: '新鲜莲白+干辣椒',
        image: '/pages/images/dish3.jpg'
      }
    ],
    showInvitePopup: false
  },

  onLoad() {
    // 页面加载时执行
    this.checkInvitePopup()
    
  },

  onShow() {
    // 页面显示时执行
  },

  // 检查是否显示邀请弹窗
  checkInvitePopup() {
    // 这里可以根据用户状态决定是否显示弹窗
    // 比如新用户首次访问时显示
    const isFirstVisit = wx.getStorageSync('isFirstVisit')
    if (!isFirstVisit) {
      this.setData({
        showInvitePopup: true
      })
      wx.setStorageSync('isFirstVisit', true)
    }
  },

  // 导航到功能页面
  navigateToFeature(e) {
    const feature = e.currentTarget.dataset.feature
    wx.navigateTo({
      url: feature.path
    })
  },

  // 导航到菜品推荐
  navigateToRecommend() {
    wx.navigateTo({
      url: '/pages/ordering/ordering?type=recommend'
    })
  },

  // 领取优惠券
  claimCoupon() {
    wx.showToast({
      title: '优惠券已领取',
      icon: 'success'
    })
  },

  // 查看全部推荐
  viewAllRecommend() {
    wx.navigateTo({
      url: '/pages/ordering/ordering?type=all'
    })
  },

  // 导航到菜品详情
  navigateToDish(e) {
    const dish = e.currentTarget.dataset.dish
    wx.navigateTo({
      url: `/pages/dish-detail/dish-detail?id=${dish.id}`
    })
  },

  // 关闭邀请弹窗
  closeInvitePopup() {
    this.setData({
      showInvitePopup: false
    })
  },

  // 邀请好友
  inviteFriends() {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    
    // 模拟邀请成功
    wx.showToast({
      title: '邀请成功！',
      icon: 'success'
    })
    
    this.closeInvitePopup()
  },

  // 分享给朋友
  onShareAppMessage() {
    return {
      title: '农家小炒 - 邀请好友赢红包',
      path: '/pages/index/index',
      imageUrl: '/pages/images/share.jpg'
    }
  },

  // 分享到朋友圈
  onShareTimeline() {
    return {
      title: '农家小炒 - 邀请好友赢红包',
      imageUrl: '/pages/images/share.jpg'
    }
  }
}) 